a, f = input(), True

try:
    int(a)
except:
    f = False


def natural(integer):
    mn = 0
    for i in range(1, integer + 1):
        if integer % i == 0:
            mn += 1
    if mn == 2:
        return True
    else:
        return False


if len(a) != 4 or not f:
    print(0)
else:
    a = int(a)
    if natural(a):
        print(a)
    else:
        itog = 0
        for i in str(a):
            i = int(i)
            if natural(i) and i > itog:
                itog = i
        for i in range(3):
            for j in range(1, 4):
                if natural(int(str(a)[i] + str(a)[j])) and int(str(a)[i] + str(a)[j]) > itog:
                    itog = int(str(a)[i] + str(a)[j])
        if natural(a // 10) and a // 10 > itog:
            itog = a // 10
        if natural(a % 1000) and a % 1000 > itog:
            itog = a % 1000
        print(itog)
